package com.sumu.utils;

import com.android.volley.toolbox.ImageLoader.ImageCache;

import android.app.Application;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

public class AppImageCache implements ImageCache{
	private static AppImageCache appImageCache;
	private static LruCache<String,Bitmap> lruCache;
	static{
		int maxMemory = (int) Runtime.getRuntime().maxMemory();
		int maxSize = maxMemory / 8;
		lruCache = new LruCache<String, Bitmap>(maxSize){
			@Override
			protected int sizeOf(String key, Bitmap value) {
				// TODO Auto-generated method stub
				return value.getHeight() * value.getRowBytes();
			}
		};
	}
	private AppImageCache(){
		
	}
	public static AppImageCache getInstance(){
		if(appImageCache == null){
			return appImageCache = new AppImageCache();
		}else{
			return appImageCache;
		}
		
	}
	@Override
	public Bitmap getBitmap(String url) {
		// TODO Auto-generated method stub
		return lruCache.get(url);
	}
	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		// TODO Auto-generated method stub
		lruCache.put(url, bitmap);
	}
	
	
	
}
